Function.prototype.call1 = function (thisArg, ...args) {
  if (typeof this !== 'function') {
    return new TypeError('error')
  }
  thisArg = thisArg || window

  const fn = Symbol('fn')
  thisArg[fn] = this
  const result = thisArg[fn](...args)
  delete thisArg[fn]
  return result
}

Function.prototype.apply1 = function (thisArg, args) {
  if (typeof this !== 'function') {
    return new TypeError('error')
  }
  thisArg = thisArg || window
  const fn = Symbol('fn')
  thisArg[fn] = this
  const result = thisArg[fn](...args)
  delete thisArg[fn]
  return result
}

Function.prototype.bind1 = function (thisArg, ...args) {
  if (typeof this !== 'function') {
    return new TypeError('error')
  }
  let self = this
  let fnbind = function () {
    let arg = args.concat(Array.from(arguments))
    // 处理new 调用的问题
    self.apply(this instanceof self ? this : thisArg, arg)
  }
  fnbind.prototype = Object.create(self.prototype)
  return fnbind
}

function ttq (params) {
  console.log(this.name);
  console.log(params);
}

const obj = {
  name: 'ttq'
}

let a = ttq.bind1(obj, 12345)
a()


function debounce (fn, wait) {
  let timer
  return function () {
    const _this = this
    const args = arguments
    clearTimeout(timer)
    timer = setTimeout(() => {
      fn.apply(_this, args)
    }, wait)
  }
}

